//
//  YCMoreViewController.m
//  LOLBox
//
//  Created by mac on 15-4-1.
//  Copyright (c) 2015年 Honey. All rights reserved.
//

#import "YCMoreViewController.h"
#import "YCMoreCell.h"
#import "UIColor+ColorPlus.h"
#import "YCMoreModel.h"

@interface YCMoreViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;

@end

@implementation YCMoreViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self createNavTitleView:@"更多"];
        [self initData];
    }
    return self;
}
//初始化数据

- (void)initData
{
    self.dataSource = [NSMutableArray array];
    
    //第一组
    YCMoreModel *m1_1 = [[YCMoreModel alloc] init];
    m1_1.title = @"设置";
    YCMoreModel *m1_2 = [[YCMoreModel alloc] init];
    m1_2.title = @"去掉广告";
    
    //第二组
    YCMoreModel *m2_1 = [[YCMoreModel alloc] init];
    YCMoreModel *m2_2 = [[YCMoreModel alloc] init];
    YCMoreModel *m2_3 = [[YCMoreModel alloc] init];
    
    m2_1.title = @"个人空间";
    m2_2.title = @"修改绑定的召唤师";
    m2_3.title = @"金币: 0";
    
    m2_1.icon = @"icon_shen";
    m2_3.icon = @"user_gold";
    
    m2_3.detail = @"可兑换Q币、点券";
    
    //第三组
    YCMoreModel *m3_1 = [[YCMoreModel alloc] init];
    YCMoreModel *m3_2 = [[YCMoreModel alloc] init];
    YCMoreModel *m3_3 = [[YCMoreModel alloc] init];
    YCMoreModel *m3_4 = [[YCMoreModel alloc] init];
    
    m3_1.title = @"视频播放历史";
    m3_2.title = @"视频缓存";
    m3_3.title = @"英雄配音缓存";
    m3_4.title = @"收藏的文章";
    
    
    //第四组
    YCMoreModel *m4_1 = [[YCMoreModel alloc] init];
    YCMoreModel *m4_2 = [[YCMoreModel alloc] init];
    YCMoreModel *m4_3 = [[YCMoreModel alloc] init];
    YCMoreModel *m4_4 = [[YCMoreModel alloc] init];
    YCMoreModel *m4_5 = [[YCMoreModel alloc] init];
    
    m4_1.title = @"数据版本更新";
    m4_2.title = @"更新日志";
    m4_3.title = @"常见问题解答";
    m4_4.title = @"意见反馈";
    m4_5.title = @"关于我们";
    
    m4_1.detail = @"当前数据150031";
    
    //放到数组
    NSArray *arr1 = @[m1_1,m1_2];
    NSArray *arr2 = @[m2_1,m2_2,m2_3];
    NSArray *arr3 = @[m3_1,m3_2,m3_3,m3_4];
    NSArray *arr4 = @[m4_1,m4_2,m4_3,m4_4,m4_5];
    
    [self.dataSource addObject:arr1];
    [self.dataSource addObject:arr2];
    [self.dataSource addObject:arr3];
    [self.dataSource addObject:arr4];
    
    [self.tableView reloadData];
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createBgView];
    
    [self initTableView];
}

- (void)createBgView
{
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:self.view.frame];
    imgView.image = [UIImage imageNamed:@"contentview_image_hd_default"];
    [self.view addSubview:imgView];
}

- (void)initTableView
{
    //CGRect rect = [UIScreen mainScreen].bounds;
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width , self.view.frame.size.height - 64 - 50) style:UITableViewStyleGrouped];
    
    //self.tableView = [[UITableView alloc] initWithFrame:rect style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 47;
    //self.tableView.sectionHeaderHeight = 10;
    

    self.tableView.backgroundColor = [UIColor colorWithIRed:236 green:234 blue:226 alpha:1];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    /**
     *  去掉多余的线
     */
    UIView *v = [[UIView alloc] init];
    v.backgroundColor = [UIColor clearColor];
    self.tableView.tableFooterView = v;
    
    // 注册Cell
    [self.tableView registerNib:[UINib nibWithNibName:@"YCMoreCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    [self.view addSubview:self.tableView];
    
}
#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataSource.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *arr = self.dataSource[section];
    return arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YCMoreCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    NSArray *arr = self.dataSource[indexPath.section];
    YCMoreModel *model = arr[indexPath.row];
    NSInteger cnt = arr.count;
    NSInteger value;
    
    if (indexPath.row == 0)
    {
        value = 0;
    }
    else if (indexPath.row == cnt - 1)
    {
        value = 2;
    }
    else
    {
        value = 1;
    }
    
    [cell fillCellWithModel:model withValue:value withIndexPath:indexPath];
    
    return cell;
}

#pragma mark - UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 47;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
